package com.pony.controller;

import com.pony.entity.Cplb;
import com.pony.entity.Yg;
import com.pony.service.YgService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@RequestMapping("/yg")
@Controller
public class YgController {

    @Autowired
    private YgService ygService;


    @RequestMapping("/getAllYg")
    public String getAllYg(Model model) {
        List<Yg> list = ygService.getAll();
        model.addAttribute("list", list);
        return "yg";
    }

    @RequestMapping("/delYg")
    public String delYg(int id){
        ygService.delYg(id);
        return "redirect:/yg/getAllYg.do";
    }

    @RequestMapping("/toUpdateYg")
    public String toUpdateYg(@Param("id") int id, Model model) {
        Yg yg = ygService.getYgById(id);
        model.addAttribute("yg", yg);
        return "ygUpdate";
    }

    @RequestMapping("/updateYg")
    public String updateYg(Yg yg) {
        ygService.updateYg(yg);
        return "redirect:/yg/getAllYg.do";
    }

    @RequestMapping("/toTj")
    public String toTj(Model model) {
        List<Yg> ygList = ygService.getAll();
        model.addAttribute("ygList", ygList);
        return "ygtj";
    }

    @RequestMapping("/addYg")
    public String addYg(Yg yg) {
        ygService.addYg(yg);
        return "redirect:/yg/getAllYg.do";
    }
}
